package com.zcx.qshop.conn;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONObject;

import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.AsyType;
import com.zcx.helper.http.note.HttpInlet;

@HttpInlet(Conn.INLET_JSON_GOODINFO)
public class JsonGoodinfoAsyGet extends QSAsyGet<JsonGoodinfoAsyGet.Info> {

	public String uid = "", gid = "";

	public JsonGoodinfoAsyGet(String uid, String gid, AsyCallBack<Info> asyCallBack) {

		super(asyCallBack);

		this.uid = uid;
		
		this.gid = gid;

		ASY_TYPE = AsyType.MAX_STALE;
		
 	}
	
	@Override
	public Info parser(JSONObject object) {
		
		if(object.optString("message").equals("1")){
			
			Info info = new Info();
			
			info.title = object.optString("title");
			
			info.price = object.optString("price");
			
			info.unit = object.optString("unit");
			
			info.number = object.optString("number");
			
			info.description = object.optString("description");
			
			info.renumber = object.optString("renumber");
			
			info.type = object.optString("type");

			info.isshoucang = object.optString("isshoucang");
			
			JSONArray array = object.optJSONArray("piclist");
			
			for (int i = 0; i < array.length(); i++) {
				
				Info.Picurl picurl = new Info.Picurl();
				
				picurl.picurl = Conn.SERVICE + array.optString(i);
						
				info.picurls.add(picurl);
				
			}
			
			return info;
			
		} 
		
 		return null;
 		
	}

	public static class Info implements Serializable{
		
		public String gid, title, price, unit, number, description, renumber, type, isshoucang;
		
		public List<Picurl> picurls = new ArrayList<Picurl>();
		
		public static class Picurl implements Serializable{
			
			public String picurl;
			
		} 
		
	}
	
}
